#include "head.h"

/* Usage: 客户端 */

int do_rm(client_status_t *client){
    char path[200] = {0};
    for(int i=0; i<strlen(client->runtime_cmd); i++){
        path[i] = client->runtime_cmd[i+3];
    }
    self_defined_pro_t *protect = (self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t *));
    
    protect->para_num = 3;
    if(protect->para_num == 3){
        //直接传给服务端
        memset(protect, 0, sizeof(self_defined_pro_t));
        strcat(protect->message, "/");
        strcpy(protect->message, client->user);
        strcat(protect->message, "/");
        strcat(protect->message, path);
        protect->cmd = 4;
        protect->message_len = strlen(protect->message);
        protect->para_num = 3;
        send(client->socket_fd, protect, sizeof(self_defined_pro_t), MSG_NOSIGNAL);
        return 0;
    }
    self_defined_pro_t *mes=(self_defined_pro_t *)calloc(1,sizeof(self_defined_pro_t));
    recv(client->socket_fd, mes, sizeof(self_defined_pro_t), MSG_WAITALL);
    //接收服务端的信息
    if(mes->cmd == 4 && mes->para_num == 2){
        char command[200] = {0};
        strncpy(command, "rm -r ", 3);
        strncpy(command, mes->message, strlen(mes->message));
        system(command);
        return 0;
    }
    else{
        return -1;
    }
    free(protect);
    free(mes);
    return 0;
}

